<?php
class SF_Passport_CustomerController extends Mage_Core_Controller_Front_Action
{

	//判断是否已登录
	public function preDispatch()
    {
       	parent::preDispatch();
 
       	if (!Mage::getSingleton('customer/session')->authenticate($this)) 
       	{
            $this->setFlag('', 'no-dispatch', true);
        }
    }

	public function indexAction()
	{
		$this->loadLayout();
		$this->renderLayout();
	}

	public function saveAction()
	{
	    $passportData = $this->getRequest()->getParams();
	    $customId   = $passportData['cust_id'];
	    $fristName  = $passportData['frist_name'];
	    $middleName = $passportData['middle_name'];
	    $lastName   = $passportData['last_name'];
	    $passportNo = $passportData['passport_no'];
	    $issueDate  = $passportData['issue_date'];
	    
	    $rs = Mage::helper('passport')->save($customId, $fristName, $middleName, $lastName, $passportNo, $issueDate);
	    if($rs)
	    {
	        Mage::getSingleton('core/session')->addSuccess(Mage::helper('passport')->__('Save success.'));
	        $this->_redirect('*/*/index');
	    }
	    else
	    {
	        Mage::getSingleton('core/session')->addSuccess(Mage::helper('passport')->__('Save failed.'));
	        $this->_redirect('*/*/index');
	    }
	    
	    
	}

	
	public function checkoutsaveAction()
	{
	    $passportData = $this->getRequest()->getParams();
	    $customId   = $passportData['cust_id'];
	    $fristName  = $passportData['frist_name'];
	    $middleName = $passportData['middle_name'];
	    $lastName   = $passportData['last_name'];
	    $passportNo = $passportData['passport_no'];
	    $issueDate  = $passportData['issue_date'];
	     
	    $rs = Mage::helper('passport')->save($customId, $fristName, $middleName, $lastName, $passportNo, $issueDate);
	    if($rs)
	    {
	        Mage::getSingleton('core/session')->addSuccess(Mage::helper('passport')->__('Save success.'));
	        $this->_redirectUrl(Mage::getUrl('checkout/onepage/index'));
	    }
	    else
	    {
	        Mage::getSingleton('core/session')->addSuccess(Mage::helper('passport')->__('Save failed.'));
	        $this->_redirectUrl(Mage::getUrl('checkout/onepage/index'));
	    }
	}
	
	
}